import { createApp } from "vue";
import App from "./App.vue";
import router from "./router/router";
import { ElMessage } from 'element-plus'
import ElementPlus from 'element-plus';
import 'element-plus/theme-chalk/index.css';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

// import locale from 'element-plus/lib/locale/lang/zh-cn'
app.use(router)
// .use(scroll)
app.use(ElementPlus)
app.mount("#app");


router.beforeEach((to, from, next) => {
    // console.log(to)
    if(to.path == '/')
    {
        next({ path: '/IndexHome/homePage' })
    }
    let store = localStorage.getItem("Token");
    if (to.meta.requireAuth) {
        if (store) {
            next()
        } else {
            ElMessage.error("登录过期")
            next({ path: '/LoginPage' })
        }
    } else {
        next()
    }
})

